<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="pojo.User" %>
<%@ page import="utils.db.impl.DeviceFetcher" %>
<%@ page import="utils.db.impl.UserFetcher" %>
<%@ page import="java.util.List" %>
<%@ page import="pojo.Device" %>
<%@ page import="tools.Translator" %>

<%
User user=(User)session.getAttribute("user");

%>
<%if (session.getAttribute("user") == null) {%>
<h1>Brak dostępu do tej strony!</h1>
<%}else{ 
	int id = user.getId();
%>

<div id="gallery_container">
<h1>Statusy oddanych urządzeń przez klientów</h1>
<table style="width: 700px; ">
<tr>
<td style="width: 150px; height: 40px; text-align: center;"><b>Typ</b></td>
<td style="width: 200px; height: 40px; text-align: center;"><b>Opis</b></td>
<td style="width: 150px; height: 40px; text-align: center;"><b>Data oddania</b></td>
<td style="width: 150px; height: 40px; text-align: center;"><b>Status</b></td>
<td style="width: 150px; height: 40px; text-align: center;"><b>Klient</b></td>
</tr>
<%
				DeviceFetcher fetcher = new DeviceFetcher();
				List<Device> devices = fetcher.getDevicesByIdServiceman(id); 
				
				for(int i=0;i<devices.size();i++){
					UserFetcher u = new UserFetcher();
					User client = u.getUserById(devices.get(i).getClientId());
					String clientName = client.getFirstName();
					String clientSurname = client.getLastName();
				%>
<tr>
<td style="width: 150px; height: 40px; text-align: center;"><%= Translator.toPolish(String.valueOf(devices.get(i).getType()))%></td>
<td style="width: 200px; height: 40px; text-align: center;"><%= devices.get(i).getDescription()%></td>
<td style="width: 150px; height: 40px; text-align: center;"><%= devices.get(i).getDate()%></td>
<td style="width: 150px; height: 40px; text-align: center;"><%= Translator.toPolish(String.valueOf(devices.get(i).getState()))%></td>
<td style="width: 150px; height: 40px; text-align: center;"><%= clientName%> <%=clientSurname %></td>
</tr> 
<%} %>
</table>

</div>
<%} %>






